<template>
	<view class="card" v-for="item in liveData" :key="item" @click="toLive(item.roomid)">
		<view class="left">
			<image :src="item.share_img" mode=""></image>
		</view>
		<view class="right">
			<text>{{ item.name }}</text>
			<br>
			{{ item.anchor_name }}
			<view class="bottom">
				{{ time(item.start_time) }}
				<!-- {{item.start_time}} -->
			</view>
		</view>
	</view>
</template>

<script>
	import {
		liveGetList
	} from '@/api/miniApp.js'
	import {mixin} from '@/static/mixin.js'
	export default {
		mixins:[mixin],
		data() {
			return {
				liveData: {}
			};
		},
		methods: {
			time(time) {
				let date = new Date(time * 1000) ; //时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let Y = date.getFullYear() + '-';
				let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
				let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
				let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
				let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
				return Y + M + D + h + m + s;
			},
			toLive(id) {
				uni.navigateTo({
					url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${id}`
				})
			}
		},
		created() {
			let that = this;
			liveGetList({
				appid: 'wx2d0afc7e102fbc39'
			}).then(res => {
				that.liveData = res.list;
			})
		}
	};
</script>

<style scoped lang="scss">
	@import '../../static/font.scss';
	.card {
		background-color: #fff;
		display: flex;
		box-sizing: border-box;
		margin: 10px;
		border-radius: 10px;
		overflow: hidden;
		height: 130px;

		.left {
			width: 50%;
			height: 100%;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.right {
			width: 50%;
			padding: 10px;
			position: relative;

			text {
				font-size: $uni-text-size-md
			}

			.info {
				color: $uni-text-color-grey;
				display: inline-block;
				white-space: nowrap;
				width: 100%;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.bottom {
				position: absolute;
				bottom: 20px;
			}
		}
	}
</style>
